﻿using Example;
using HttpClientHelper;
using KinTN_WMS_CL.DialogView;
using KinTN_WMS_CL.Extensions;
using KinTN_WMS_CL.UserControlModels;
using KinTN_WMS_CL.UserControls;
using KinTN_WMS_CL.Views;
using LogHelper;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Http;
using Prism.Events;
using Prism.Ioc;
using Prism.Modularity;
using Prism.Regions;
using System;
using System.Net.Http;
using System.Windows;

namespace KinTN_WMS_CL
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App
    {
        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }

        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            // Add modules here
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterForNavigation<InView, InViewModel>("In");
            containerRegistry.RegisterForNavigation<AGVView>("AGV");
            containerRegistry.RegisterForNavigation<CommonalityView>("Commonality");
            containerRegistry.RegisterForNavigation<ErrorView>("Error");
            containerRegistry.RegisterForNavigation<OutView>("Out");
            containerRegistry.RegisterForNavigation<HomeView, HomeViewModel>("Home");
            containerRegistry.RegisterForNavigation<InterfaceView, InterfaceViewModel>("Interface");
            containerRegistry.RegisterForNavigation<MaterialStorageView, MaterialStorageViewModel>("StockBin");
            containerRegistry.RegisterForNavigation<QuestView>("Quest");
            containerRegistry.RegisterForNavigation<RefundView>("Refund");

            containerRegistry.RegisterSingleton<IEventAggregator, EventAggregator>();
            containerRegistry.RegisterDialog<MaterialStorageDetailsView, MaterialStorageDetailsViewModel>();
            var serviceCollection = new ServiceCollection();
            serviceCollection.AddHttpClient();  // Adds the default IHttpClientFactory

            // Build the service provider
            var serviceProvider = serviceCollection.BuildServiceProvider();

            // Configure your services
            var httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>();

            // Register the IHttpClientFactory with the Prism container
            containerRegistry.RegisterInstance(httpClientFactory);
            // 注册类型和服务
            containerRegistry.RegisterSingleton<IHttpClients, HttpClients>();
            containerRegistry.RegisterSingleton<ILogServices, LogServices>();
        }
    }
}
